package ay.shadow.common.rabbitmq.demo;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.util.Scanner;

/**
 * 模拟发送消息
 *
 * @author shadow
 */
public class SendDemo {

    private static final String EXCHANGE_DIRECT_NAME = "shadow-exchange-direct";

    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("8.130.103.38");
        factory.setUsername("admin");
        factory.setPassword("admin");
        try {
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            //四种交换机类型，分别是Direct 、Fanout 、Topic 、Headers
            while (true) {
                channel.basicPublish(EXCHANGE_DIRECT_NAME, "error", null, new Scanner(System.in).next().getBytes());
            }
        } catch (Exception e) {

        }
    }
}
